package zifuchuan;

public class _02翻转字符串 {

    public static void main(String[] args) {
        String initString = "abcde";
        String reverse = reverse(initString);
        System.out.println(reverse);


        //反转指定部分，如“abcdefg“转为”afedcbg”
        String s = "abcdefg";
        String substring = s.substring(1, 6);
        String s1 = reverseInIndex(substring);
        String replace = s.replace(substring, s1);
        System.out.println(replace);

    }
    public static String reverseInIndex(String substring){
        char[] reverse = new char[substring.length()+1];
        for (int i = 0 ; i < substring.length() ;i ++){
            reverse[i] = substring.charAt(substring.length() - 1 -i);
        }
        return new String(reverse);
    }



    public static String reverse(String intiString){
        int length = intiString.length();
        char[] reverse = new char[intiString.length()];
        for (int i = 0 ; i < intiString.length(); i++){
            reverse[i] = intiString.charAt(intiString.length() - 1 -i);
        }
        return new String(reverse);
    }
}


/*
public class Reverse {
    public String reverseString(String iniString) {
        StringBuffer sb = new StringBuffer(iniString);
        return sb.reverse().toString();
    }
}*/